package org.lds.scheduled.job.common.autoconfigure;

import org.lds.scheduled.job.common.annotation.LogAspect;
import org.lds.scheduled.job.common.autoconfigure.etcd.EtcdClient;
import org.lds.scheduled.job.common.autoconfigure.etcd.EtcdProperties;
import org.lds.scheduled.job.common.autoconfigure.etcd.EtcdService;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({EtcdProperties.class})
public class CommonAutoConfiguration {
    private final EtcdProperties etcdProperties;

    public CommonAutoConfiguration(EtcdProperties etcdProperties) {
        this.etcdProperties = etcdProperties;
    }

    @Bean
    public LogAspect logAspect() {
        return new LogAspect();
    }

    @Bean
    public EtcdService etcdService() {
        EtcdClient etcdClient = new EtcdClient(etcdProperties.getEndpoints());
        return new EtcdService(etcdClient);
    }

}
